<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="params.orderSn" placeholder="请输入流水单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="params.userName" placeholder="请输入姓名" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="params.userPhone" placeholder="请输入手机号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <hospitalListbth v-model="params.hospitalName" @childfun="childfun" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="交易单号">
              <el-input v-model="params.merTrace" placeholder="请输入交易单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="支付时间" prop="province">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单状态" prop="province">
              <el-select v-model="params.guaranteeType" placeholder="请选择">
                <el-option label="未担保" :value="0"></el-option>
                <el-option label="担保中" :value="1"></el-option>
                <el-option label="完成结算" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminMerchantOrderProvider.export') !=-1"
              type="primary"
              @click="exfun"
            >导出</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminMerchantOrderProvider.refresh') !=-1"
              type="primary"
              @click="refree"
            >刷新</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <!-- table列表 -->
      <el-table :data="tableData" class="tableData">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        />
        <el-table-column prop="orderSn" label="流水单号" align="center" />
        <el-table-column prop="hospitalName" label="医院名称" align="center" />
        <el-table-column prop="reimbursementRatio" label="回款比率" align="center" />
        <el-table-column prop="userName" label="客户姓名" align="center" />

        <el-table-column prop="userPhone" label="客户手机号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.userPhone |phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="allPrice" label="扣除杂费金额" align="center" />
        <el-table-column prop="sundryPrice" label="杂费金额" align="center" />
        <el-table-column prop="outOrderId" label="业务单号" align="center" />
        <el-table-column prop="merTrace" label="交易单号" align="center" />
        <el-table-column prop="payType" label="支付方式" align="center">
          <!-- <template slot-scope="scope">
            <span v-if="scope.row.payType==1">信用卡快捷支付</span>
            <span v-if="scope.row.payType==2">借记卡快捷支付</span>
            <span v-if="scope.row.payType==3">微信支付</span>
            <span v-if="scope.row.payType==4">支付宝支付</span>
          </template>-->
        </el-table-column>
        <el-table-column prop="bizOrderAmount" label="支付金额" align="center" />
        <el-table-column prop="merchantSplitAmount" label="子商户分账金额" align="center" />
        <el-table-column prop="comAmt" label="手续费金额" align="center" />
        <el-table-column prop="mmkSplitAmount" label="平台分账金额" align="center" />
        <el-table-column prop="guaranteeType" label="订单状态" align="center" />

        <el-table-column prop="createdAt" label="支付时间" align="center" />
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              v-if="permissionJson.indexOf('AdminMerchantOrderProvider.detail') !=-1"
              type="text"
              size="small"
              @click="edit(scope.row)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="params.pageNum"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="params.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import hospitalListbth from "@/components/hospitalList";
import abnormallist from "@/api/abnormallist/normallist";
import { exportfile } from "@/api/exporfile";
export default {
  components: {
    hospitalListbth
  },
  name: "normallist",
  data() {
    return {
      // loading层
      tableLoading: false,
      time: "",
      tableData: [{}],
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      total: 0,
      params: {
        payStartTime: "",
        payEndTime: "",
        targetId: -1,
        userPhone: "",
        userName: "",
        // hospitalName:"",
        merTrace: "",
        orderSn: "",
        pageNum: 1,
        pageSize: 20
      }
    };
  },
  watch: {
    time(val) {
      this.params.payStartTime = val ? val[0] : "";
      this.params.payEndTime = val ? val[1] : "";
    }
  },
  mounted() {
    this.list();
  },
  methods: {
    exfun() {
      abnormallist.exportfun(this.params).then(res => {
        exportfile(res);
      });
    },
    refree(data) {
      abnormallist.refresh().then(res => {
        this.$message({
          type: "warning",
          message: res.data.msg
        });
        if (res.data.code == 0) {
          this.list();
        }
      });
    },
    list() {
      this.tableLoading = true;
      abnormallist.list(this.params).then(res => {
        // console.log(res)
        if (res.data.code == 0) {
          // console.log(res.data);
          this.total = res.data.data.count;
          this.tableData = res.data.data.list;
          this.tableLoading = false;
        } else {
          this.$message({
            type: "warning",
            message: res.data.msg
          });
        }
      });
    },
    edit(datas, type) {
      // 详情
      this.$router.push({
        name: "abnormaldetail",
        query: { orderId: datas.orderId }
      });
    },
    searchfun() {
      // console.log(this.params);
      this.params.pageNum = 1;
      this.list();
    },
    childfun(res) {
      this.params.targetId = res.id ? res.id : -1;
      // this.params.hospitalName = res.value ;
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.tableData{

       width:99.9%!important;

}
</style>
